import { View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { useState, useEffect, useCallback } from "react";
import { useDispatch, useSelector } from 'react-redux';

//公共组件
import LgNavCustomBar from '../../components/navCustomBar'

import LgSelectModalEdu from "../LGcomponents/LgSelectModalEdu";
import { getStorage } from '../../components/utils'
import Utils from '../../../utils'
import "./index.scss";

const storage = getStorage()

function App() {

  const dispatch = useDispatch()

  const onConfirm = useCallback((data) => {
    console.log(data)
    storage.set('toChooseObject', JSON.stringify(data))
    dispatch({ type: 'SET_SELECTUSERLIST', data: data })

    Taro.navigateBack({});
    // let url = '/pages/scheduleApp/createSchedule/index'
    // Taro.navigateTo({
    //   url
    // })
  }, []);

  useEffect(() => {
    console.log(JSON.parse(storage.get('toChooseObject')))
  }, []);

  return (
    <View className="new_select_modal">
      <LgNavCustomBar
        mainTitle={'选择对象'}
        needMainIcon={process.env.TARO_ENV === 'weapp' ? false : true}
        needBackIcon={true}
        isTitlePositionLeft={true}
        mainTitleBold={false}
      ></LgNavCustomBar>
      <View className="new_select_body">
        <LgSelectModalEdu
          backData='all'
          token={Utils.getQueryVariable('lg_tk')}
          officeUrl={storage.get('itemUrl') || ""}
          selectUserList={JSON.parse(storage.get('toChooseObject'))}
          recentList={JSON.parse(storage.get('toChooseObject'))}
          onConfirm={onConfirm}
        ></LgSelectModalEdu>
      </View>
    </View>
  );
}
export default App;
